package com.szd.qiongyou20.home.search.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.szd.qiongyou20.R;
import com.szd.qiongyou20.home.search.bean.MddBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by SZD on 2016/12/26.
 */

public class Mdd_ListView_Adapter extends BaseAdapter {

    private Context mContext;
    private List<MddBean.DataBean.EntryBean> mList;

    public Mdd_ListView_Adapter(Context context, List<MddBean.DataBean.EntryBean> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_searche_mdd, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // 获取数据
        String photo = mList.get(position).getPhoto();
        String cnname = mList.get(position).getCnname();
        String enname = mList.get(position).getEnname();
        String label = mList.get(position).getLabel();
        String parentname = mList.get(position).getParentname();
        String beenstr = mList.get(position).getBeenstr();
        boolean has_mguide = mList.get(position).isHas_mguide();

        // 将数据添加到View中
        Glide.with(mContext).load(photo).into(holder.mImageViewSearchMdd);
        holder.mTextViewSearchCnname.setText(cnname);
        holder.mTextViewSearchEnname.setText(enname);
        holder.mTextViewSearchType.setText(label);
        holder.mTextViewSearchCountry.setText(parentname);
        holder.mTextViewSearchCount.setText(beenstr);
        if (!has_mguide)
            holder.mImageViewMark.setVisibility(View.INVISIBLE);

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.imageView_search_mdd)
        ImageView mImageViewSearchMdd;
        @Bind(R.id.textView_search_cnname)
        TextView mTextViewSearchCnname;
        @Bind(R.id.textView_search_enname)
        TextView mTextViewSearchEnname;
        @Bind(R.id.textView_search_type)
        TextView mTextViewSearchType;
        @Bind(R.id.textView_search_country)
        TextView mTextViewSearchCountry;
        @Bind(R.id.textView_search_count)
        TextView mTextViewSearchCount;
        @Bind(R.id.imageView_mark)
        ImageView mImageViewMark;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
